package com.homegoods.orderinfodetail.presenter;

import com.homegoods.classify.model.Constant;
import com.homegoods.orderinfodetail.model.CommentModel;
import com.kedll.library.mvp.AbstractRefreshPresenter;
import com.kedll.library.mvp.RefreshingView;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author QiQi
 */
public class GoodsCommentListPresenter extends AbstractRefreshPresenter<RefreshingView> {

    private Random random = new Random();

    public GoodsCommentListPresenter(RefreshingView view, String id) {
        super(view);
    }

    public void loadAll() {
        refreshData();
    }

    public void loadImage() {
        refreshData();
    }

    @Override
    protected void fetchData(boolean isLoadMore) {

        addSubscription(Observable.range(0, 12)
                .map(integer -> {
                    CommentModel commentModel = new CommentModel();
                    commentModel.setColor("颜色：红色");
                    commentModel.setComment("很喜欢，非常好，满分");
                    commentModel.setDate("2018-09-23");
                    commentModel.setHeadUrl(Constant.TEST_IMG_URL + ((page * PER_PAGE_COUNT) + integer));
                    commentModel.setPhoneNum("12345678909");
                    commentModel.setScore(random.nextInt(5));
                    commentModel.setSize("尺寸：XL");
                    List<String> imgs = new ArrayList<>();
                    int count = random.nextInt(7);
                    for (int i = 0; i < count; i++) {
                        String img = Constant.TEST_IMG_URL + random.nextInt(100);
                        imgs.add(img);
                    }

                    commentModel.setImgs(imgs);
                    commentModel.setGoodNum(String.valueOf(random.nextInt(100)));
                    return commentModel;
                })
                .toList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(r -> parserData(isLoadMore, r), new HttpErrorListener(isLoadMore)));

    }


}